package com.sjx.onelinecord.kotlininvoke

class Person {

    /**
     * java习惯写的回调
     */
    var mListener: MyInterface? = null

    fun setPersonListener(mListener: MyInterface) {
        this.mListener = mListener
        mListener.println()
    }

    interface MyInterface {

        fun println()

    }

    /**
     * kotlin习惯写的回调
     * person.setInvokeListener { println(it) } -- 主方法回调语句
     */
    val name = "sjx"

    lateinit var listener: (Int) -> Unit
    //也可以写成 lateinit var listener : (String) -> Unit
    //fun setInvokeListener(listener: (String) -> Unit
    //listener?.invoke("name:$name")

    fun setInvokeListener(listener: (Int) -> Unit) {
        this.listener = listener
        listener?.invoke(77)
    }

}